﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CharcterPanel : MonoBehaviour
{
    private static CharcterPanel instance;
    public static CharcterPanel MyInstance
    {
        get
        {
            if (instance == null)
            {
                instance = FindObjectOfType<CharcterPanel>();
            }
            return instance;
        }
    }
    [SerializeField]
    private charButton shirt, chest, plate, shoulders, hands, bracers, cape, belt, legs, feet, mainHand, offhand, ring2, ring, neck, trincket, headCovering, head, twohand;
    [SerializeField]
    private CanvasGroup canvasGroup;
    public charButton MyCharbutton { get; set; }
    public void Toggle()
    {
        canvasGroup.alpha = canvasGroup.alpha > 0 ? 0 : 1;
        canvasGroup.blocksRaycasts = canvasGroup.blocksRaycasts ==true ? false : true;
    }

    public void EquipArmor(Equipment equipment)
    {
        switch (equipment.MyType)
        {
            case EquipmentType.Shirt:
                shirt.EquipArmor(equipment);
                break;
            case EquipmentType.Chest:
                chest.EquipArmor(equipment);
                break;
            case EquipmentType.Plate:
                plate.EquipArmor(equipment);
                break;
            case EquipmentType.Shoulders:
                shoulders.EquipArmor(equipment);
                break;
            case EquipmentType.Hands:
                hands.EquipArmor(equipment);
                break;
            case EquipmentType.Bracers:
                bracers.EquipArmor(equipment);
                break;
            case EquipmentType.Cape:
                cape.EquipArmor(equipment);
                break;
            case EquipmentType.Belt:
                belt.EquipArmor(equipment);
                break;
            case EquipmentType.Legs:
                legs.EquipArmor(equipment);
                break;
            case EquipmentType.Feet:
                feet.EquipArmor(equipment);
                break;
            case EquipmentType.MainHand:
                mainHand.EquipArmor(equipment);
                break;
            case EquipmentType.Offhand:
                offhand.EquipArmor(equipment);
                break;
            case EquipmentType.Twohand:
                twohand.EquipArmor(equipment);
                break;
            case EquipmentType.Ring:
                
                //if (ring.transform.GetChild(0).GetComponent<Image>().enabled == true )
                //{
                //   
                //}
                //else if (ring2.transform.GetChild(0).GetComponent<Image>().enabled == true)
                //{
                //  
                //}else
                //{
                //    
                //}
                if (ring.MyEquippedEquipment == null)
                {
                    ring.EquipArmor(equipment);
                }
                else if (ring2.MyEquippedEquipment == null)
                {
                    ring2.EquipArmor(equipment);
                }
                else
                {
                    ring.EquipArmor(equipment);
                }
                break;
            case EquipmentType.Neck:
                neck.EquipArmor(equipment);
                break;
            case EquipmentType.Trincket:
                trincket.EquipArmor(equipment);
                break;
            case EquipmentType.HeadCovering:
                headCovering.EquipArmor(equipment);
                break;
            case EquipmentType.Head:
                head.EquipArmor(equipment);
                break;
            
        }
    }

}
